/**
 * Created by Noir on 1/26/14.
 */
'use strict'

angular.module('2order.user').controller('UserListController',['$scope','$location','Users','$http', function($scope, $location, Users, $http){
    $scope.test = 'alo';
    // load all user list
    Users.query({}, function(users){
        $scope.users = users;
    });
}]);

angular.module('2order.user').controller('ProfileController',['$scope','$location','Users','$http','$routeParams','UserSession', function($scope, $location, Users, $http, $routeParams, Session){
    $scope.isNotMe = false;
    $scope.status = 'unfollow';
    // first, get user's profile
    Users.get({signature:$routeParams.signature}, function(user){
        $scope.owner = user;
        // update isNotMe
        if($scope.owner._id == Session.userId || $scope.owner.username == Session.username){
            $scope.isNotMe = false;
        }else{
            // check follow status if it's not me
            for(var i=0;i<$scope.owner.followed.length;i++){
                var follower = $scope.owner.followed[i];
                if(Session.userId == follower.userId){
                    $scope.status = 'followed';
                    break;
                }
            }

            $scope.isNotMe = true;
        }
    });


}]);


